//
// Created by alice on 25-4-23.
//

#include "Move.h"

double Rotation::operator()(double &target, const double &angular) const {
    Change(target,angular, 2 * M_PI ,RotationCheck);
    return target;
}


double RotationCheck(double & target , const double & Max) {
    if (target > Max) {
        target -= floor(target / Max ) * Max;
    }
    return target;
}

double SpeedCheckUP(double & target , const double & Max) {
    target = target >= Max ? Max : target;
    return target;
}

double SpeedCheckDown(double &target, const double &Max) {
    target = target<= Max ? Max : target;
    return target;
}
void Velocity::speedCheck() {
    if (speed == speedMax) {
        status = MAX;
    }
    else {
        status = speed < speedMax ? UP : DOWN;
    }
}


Velocity Velocity::run() {
    speedCheck();
    switch (status) {
        case UP: {
            Change(speed,acceleration , speedMax , SpeedCheckUP);
        }
        case MAX: {
            break;
        }
        case DOWN: {
            Change(speed , -acceleration , speedMax ,SpeedCheckDown);
        }
    }
    return *this;
}

void Velocity::changeAcceleration(const double &acceleration) {
    this->acceleration = acceleration;
}

void Velocity::changeSpeedMax(const double & speedMax) {
    this->speedMax = speedMax;
}

double Velocity::getAcceleration() const {
    return this->acceleration;
}

double Velocity::getSpeedMax() const {
    return this->speedMax;
}

double Velocity::getSpeed() const {
    return this->speed;
}

Location Move::operator()(Location &target, const double &orientation, const double &speed) {
    target.first = Change(target.first , speed * cos(orientation));
    target.second = Change(target.first , speed * sin(orientation));
    return target;
}
